﻿#light
#r @"..\..\libs\Interop.WMPLib.dll";;

let artCacheDir = 
    let localAppDataDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)
    sprintf @"%s\Microsoft\Media Player\Art Cache" localAppDataDir

let artCacheFile (mediaItem : WMPLib.IWMPMedia) = 
    let trackingID = mediaItem.getItemInfo("TrackingID")
    sprintf @"%s\%s" artCacheDir trackingID

let getItemInfo (mediaItem : WMPLib.IWMPMedia) = 
    let albumName = mediaItem.getItemInfo("WM/AlbumTitle")
    let artistName = mediaItem.getItemInfo("WM/AlbumArtist")
    let releaseDate = mediaItem.getItemInfo("ReleaseDate")
    let cover = mediaItem |> artCacheFile
    (albumName, artistName, releaseDate, cover)

let getAttributeNames (mediaItem : WMPLib.IWMPMedia) = 
    List.map (fun n -> mediaItem.getAttributeName(n)) [0..(mediaItem.attributeCount-1)]

let windowsMediaPlayer = new WMPLib.WindowsMediaPlayerClass()
let mediaCollection = windowsMediaPlayer.mediaCollection
let playlistAll = mediaCollection.getAll()
playlistAll.[0] |> getItemInfo

